package com.github.nuggets.model.result;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * @description:
 * @author: wangsj
 * @date: 2022/3/22 11:53 上午
 */
@Data
@Accessors(chain = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> {

    List<T> content;

    Long pageIndex;

    Long pageSize;

    Long totalPage;

    Long totalNum;


    public  static <T> PageResult<T> of(IPage page,List<T> contexts){
        return new PageResult<T>()
                .setContent(contexts)
                .setPageIndex(page.getCurrent())
                .setTotalPage(page.getPages())
                .setPageSize(page.getSize())
                .setTotalNum(page.getTotal());
    }

    public  static <T> PageResult<T> of(IPage<T> page){
        return new PageResult<T>()
                .setContent(page.getRecords())
                .setPageIndex(page.getCurrent())
                .setTotalPage(page.getPages())
                .setPageSize(page.getSize())
                .setTotalNum(page.getTotal());
    }
}
